﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Catering.Catering_Page.richang
{
    public partial class XianQingHuiBao : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            rpt_XianQingHuiBao_Load();
        }

        /// <summary>
        /// 获取列表
        /// 编写：章建国
        /// </summary>
        private void rpt_XianQingHuiBao_Load()
        {
            rpt_xiaoqinghuibao.DataSource = new Catering_Rules.XianQingHuiBao().GetList("");
            rpt_xiaoqinghuibao.DataBind();
        }

        /// <summary>
        /// 新增
        /// 编写：章建国
        /// </summary>
        /// </summary>
        /// <param name="txt_yjqk_mingchen"></param>
        /// <param name="txt_yjqk_renshu"></param>
        /// <param name="ddl_yjqk_leibie"></param>
        /// <returns></returns>
        [System.Web.Services.WebMethod]
        public static string Add(string txt_mingcheng, string ddl_leibie, string txt_fuzeren, string txt_fashengshijian, string txt_guanbishijian, string txt_zhenggaicuoshi)
        {
            string mes = "error";
            Catering_Model.XianQingHuiBao _model = new Catering_Model.XianQingHuiBao();
            Catering_Rules.XianQingHuiBao _rules = new Catering_Rules.XianQingHuiBao();
            #region 参数赋值
            _model.mingcheng = txt_mingcheng;
            _model.leibie = ddl_leibie;
            _model.fuzeren = txt_fuzeren;
            _model.fashengshijian = !string.IsNullOrEmpty(txt_fashengshijian) ? Convert.ToDateTime(txt_fashengshijian) : DateTime.Now;
            _model.guanbishijian = !string.IsNullOrEmpty(txt_guanbishijian) ? Convert.ToDateTime(txt_guanbishijian) : DateTime.Now;
            _model.zhenggaicuoshi = txt_zhenggaicuoshi;
            //日报ID_model.ribaobianhao
            #endregion 参数赋值
            if (_rules.Add(_model) > 0)
            {
                mes = "ok";
            }
            return mes;
        }

        /// <summary>
        /// 编辑应急情况
        /// 编写：章建国
        /// </summary>
        /// <param name="_id"></param>
        /// <param name="txt_yjqk_mingchen"></param>
        /// <param name="txt_yjqk_renshu"></param>
        /// <param name="ddl_yjqk_leibie"></param>
        /// <returns></returns>
        [System.Web.Services.WebMethod]
        public static string Edit(string _id, string txt_mingcheng, string ddl_leibie, string txt_fuzeren, string txt_fashengshijian, string txt_guanbishijian, string txt_zhenggaicuoshi)
        {
            int id = !string.IsNullOrEmpty(_id) ? Convert.ToInt32(_id) : 0;
            if (id <= 0) return "NO";

            Catering_Model.XianQingHuiBao _model = new Catering_Model.XianQingHuiBao();
            #region 参数赋值
            _model.id = id;
            _model.mingcheng = txt_mingcheng;
            _model.leibie = ddl_leibie;
            _model.fuzeren = txt_fuzeren;
            _model.fashengshijian = !string.IsNullOrEmpty(txt_fashengshijian) ? Convert.ToDateTime(txt_fashengshijian) : DateTime.Now;
            _model.guanbishijian = !string.IsNullOrEmpty(txt_guanbishijian) ? Convert.ToDateTime(txt_guanbishijian) : DateTime.Now;
            _model.zhenggaicuoshi = txt_zhenggaicuoshi;
            //日报ID_model.ribaobianhao
            #endregion 参数赋值
            new Catering_Rules.XianQingHuiBao().Update(_model);

            return "OK";
        }

        /// <summary>
        /// 获取单个应急情况
        /// 编写：章建国
        /// </summary>
        /// <param name="_id"></param>
        /// <returns></returns>
        [System.Web.Services.WebMethod]
        public static System.Collections.ArrayList Get(string _id)
        {
            System.Collections.ArrayList al = new System.Collections.ArrayList();
            Catering_Model.XianQingHuiBao md = new Catering_Rules.XianQingHuiBao().GetModel(Convert.ToInt32(_id));
            al.Add(md.fashengshijian.Value.ToShortDateString());
            al.Add(md.fuzeren);
            al.Add(md.guanbishijian.Value.ToShortDateString());
            al.Add(md.leibie);
            al.Add(md.mingcheng);
            al.Add(md.ribaobianhao);
            al.Add(md.zhenggaicuoshi);
            return al;
        }

        /// <summary>
        /// 删除应急情况
        /// 编写：章建国
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void rpt_xiaoqinghuibao_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "del")
            {
                int delID = Convert.ToInt32(e.CommandArgument);
                if (new Catering_Rules.XianQingHuiBao().Delete(delID))
                {
                    rpt_XianQingHuiBao_Load();
                }
            }
        }
    }
}